import IpcMainHandle, { registerServiceInstance } from '../decorator/ipc_main_handle'
import BaseService from './base_service'

class TestService extends BaseService<TestService> {
  private constructor() {
    super()
  }

  @IpcMainHandle('testService-hello')
  async hello(name: string): Promise<{ success: boolean; message: string }> {
    try {
      return {
        success: true,
        message: `Hello, ${name}! 来自测试服务的问候。`
      }
    } catch (error) {
      console.error('测试服务错误:', error)
      return {
        success: false,
        message: '测试服务异常'
      }
    }
  }

  @IpcMainHandle('testService-getTime')
  async getTime(): Promise<{ success: boolean; time?: string; message?: string }> {
    try {
      return {
        success: true,
        time: new Date().toISOString(),
        message: '获取时间成功'
      }
    } catch (error) {
      console.error('获取时间错误:', error)
      return {
        success: false,
        message: '获取时间失败'
      }
    }
  }
}

// 创建并注册服务实例
const testServiceInstance = TestService.getInstance<TestService>()
registerServiceInstance('testService', testServiceInstance)

export default testServiceInstance